<!DOCTYPE HTML>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:include="public/layout::header('角色列表')" th:remove="tag"></div>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 角色管理 <span class="c-gray en">&gt;</span> 角色列表 <a class="btn btn-success radius r btn-refresh" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c">
        <div th:replace="/role/layout::form"></div>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="admin_delall()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a href="javascript:;" onclick="admin_add('添加角色','/role/add','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加角色</a></span> <span class="r">共有数据：<strong th:text="${pageInfo.total}"></strong> 条</span> </div>
    <table class="table table-border table-bordered table-bg">
        <thead>
        <tr>
            <th scope="col" colspan="9">角色列表</th>
        </tr>
        <tr class="text-c">
           <div th:replace="/role/layout::th"></div>
            <th width="100">操作</th>
        </tr>
        </thead>
        <tbody>

        <tr class="text-c" th:each="item : ${pageInfo.list}">
            <div th:replace="/role/layout::td(${item})"></div>
            <td class="td-manage">
                <a th:unless="${item.status}" style="text-decoration:none" onclick="admin_open(this)" href="javascript:;" title="启用"><i class="Hui-iconfont"></i></a>
                <a th:if="${item.status}"  style="text-decoration:none" onClick="admin_close(this)" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>
                <a title="授权菜单" href="javascript:;" onclick="admin_setMenu(this,'授权菜单','setMenu','800','500');" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe61d;</i></a>
                <a title="编辑" href="javascript:;" onclick="admin_edit(this,'编辑','update','800','500');" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
                <a title="删除" href="javascript:;" onclick="admin_del(this)" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
        </tr>
        </tbody>
    </table>
</div>
<!--_footer 作为公共模版分离出去-->
<div th:include="public/layout::footer" th:remove="tag"></div>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
    /*
     参数解释：
     title	标题
     url		请求的url
     id		需要操作的数据id
     w		弹出层宽度（缺省调默认值）
     h		弹出层高度（缺省调默认值）
     */
    /*管理员-增加*/
    function admin_add(title,url,w,h){
        layer_show(title,url,w,h);
    }
    /*管理员-删除*/
    function admin_del(obj){
        id=get_id(obj);
        del([id]);
    }

    function del(ids) {
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: 'delete',
                dataType: 'json',
                data:{id:ids},
                success: function(data){
                    if(data.code==0){
                        layer.msg(data.msg,{icon:1,time:3000});
                        location.reload();
                    }else{
                        layer.msg(data.msg,{icon:1,time:3000});
                    }

                },
                error:function(data) {
                    console.log(data.msg);
                }
            });
        });
    }

    function admin_delall() {
        ids = [];
        $(":checked[name='id']").each(function () {
            ids.push($(this).val())
        });

        del(ids);

    }

    function get_id(obj) {
        id=$(obj).parents("tr").find("input[name='id']").val();
        return id;
    }


    /*管理员-编辑*/
    function admin_edit(obj,title,url,w,h){
        id=get_id(obj);
        url=url+"?id="+id;
        layer_show(title,url,w,h);
    }

    function admin_setMenu(obj,title,url,w,h){
        id=get_id(obj);
        url=url+"?role_id="+id;
        layer_show(title,url,w,h);
    }

    /*管理员-停用*/
    function admin_close(obj){
        id=get_id(obj);
        layer.confirm('确认要停用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……

            $.ajax({
                type: 'POST',
                url: 'close',
                dataType: 'json',
                data:{id:id},
                success: function(data){
                    if(data.code==0){
                        layer.msg(data.msg,{icon:1,time:3000});
                        location.reload();
                    }else{
                        layer.msg(data.msg,{icon:1,time:3000});
                    }

                },
                error:function(data) {
                    console.log(data.msg);
                }
            });

        });
    }

    /*管理员-启用*/
    function admin_open(obj){
        id=get_id(obj);
        layer.confirm('确认要启用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……

            $.ajax({
                type: 'POST',
                url: 'open',
                dataType: 'json',
                data:{id:id},
                success: function(data){
                    if(data.code==0){
                        layer.msg(data.msg,{icon:1,time:3000});
                        location.reload();
                    }else{
                        layer.msg(data.msg,{icon:1,time:3000});
                    }

                },
                error:function(data) {
                    console.log(data.msg);
                }
            });

        });
    }


</script>
</body>
</html>